/*
 * @(#)HAHA.java   09/11/01
 * 
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 */



/**
 *
 */
package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;

import fr.ema.arch3d.jmodel.transformXML.OperateNode;
import fr.ema.arch3d.jmodel.transformXML.TransformArch;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

//~--- classes ----------------------------------------------------------------

/**
 * class description
 *
 * @version    version 25 oct. 2009
 * @author     Huaxi (Yulin) ZHANG
 */
public class HAHA1 {

    /**
     * Method description
     *
     * @param args
     * @throws ClassNotFoundException
     * @throws IllegalAccessException
     * @throws InstantiationException
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws SAXException
     * @throws ParserConfigurationException
     * @throws TransformerException
     * @throws IOException 
     * @throws JAXBException 
     */
    public static void main(String[] args)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException, SAXException,
                   ParserConfigurationException, TransformerException, IOException, JAXBException {

        // TODO Auto-generated method stub
        JAXBContext context;

        context = JAXBContext.newInstance("fr.ema.arch3d.xoadl.specification");

      Unmarshaller unmarshaller;

      unmarshaller = context.createUnmarshaller();

 //unmarshaller.setValidating(true);
           File file = new File("E://Yulin//Nime//Code//workspace//Arch3D-Model//src//main//java//test//test.xml");

           JAXBElement o=(JAXBElement)unmarshaller.unmarshal(new FileInputStream(file)) ;
           ////           File a=XMLConfusion.xmlConfuse(file);
//        String specFile = "E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/test.xml";
//        
//        String test = "E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/testout.xml";
//        
//        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
//        DocumentBuilder builder = factory.newDocumentBuilder();
//        Document doc = builder.parse(new File(test));
//        TransformerFactory tFactory = TransformerFactory.newInstance();
//        Transformer tFormer = tFactory.newTransformer();
//        Element e=(Element) doc.getElementsByTagName("componentRole").item(0);
//        doc.getElementsByTagName("componentRoles").item(0).appendChild(e);

        
//        String cmpRoleDBUri="E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/resources/fr/ema/arch3d/database/componentRoleDB.xml";
//        String y = "E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/crQuery.xquery";
//	
//        InputStream        x       = new FileInputStream(new File(y));
//        String a=slurp(x);
//        System.out.println(a);
//        System.out.println(xQuery.select(cmpRoleDBUri, a));
// TransformArch.transformSpecXml(specFile);
//      String query="E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/crQuery.xquery";
//      //xQuery.select(file,query);
//      xQuery.selectCmpRoles(file,"A B");

       // RemoveNode.removeNode("E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/test.xml",
       //                       "componentRoles");

       // OperateNode.addIncludeNode("E:/Yulin/Nime/Code/workspace/Arch3D-Model/src/main/java/test/test.xml", "test.cml");
    }
    public static String slurp (InputStream in) throws IOException {
	    StringBuffer out = new StringBuffer();
	    byte[] b = new byte[4096];
	    for (int n; (n = in.read(b)) != -1;) {
	        out.append(new String(b, 0, n));
	    }
	    return out.toString();
	}

}
